module.exports = function(app) {
  return new Handler(app)
}

var Handler = function(app) {
  this.app = app
  Handler.app = app
  this.sessionService = this.app.get('sessionService')
  this.channelService = this.app.get('channelService')
  this.gameChanel = this.channelService.getChannel("GameChannel",true)
}

var handler = Handler.prototype

//获取任务信息
handler.getTaskInfo = function(msg,session,next) {
	var uid = session.get("uid")
	if(!uid){
		next(null,{flag : false,data : "已断开连接"})
		return
	}
	this.app.rpc.db.task.getTaskInfo(null,uid,function(flag,data) {
		next(null,{flag : flag,data : data})
	})
}

//领取任务奖励
handler.getTaskAward = function(msg,session,next) {
	var uid = session.get("uid")
	var taskId = msg.taskId
	if(!uid){
		next(null,{flag : false,data : "已断开连接"})
		return
	}
	if(!taskId){
		next(null,{flag : false,data : "taskId error"})
		return
	}
	this.app.rpc.db.task.getTaskAward(null,uid,taskId,function(flag,data) {
		next(null,{flag : flag,data : data})
	})
}

//领取红包任务奖励
handler.getRedTaskAward = function(msg,session,next) {
	var uid = session.get("uid")
	if(!uid){
		next(null,{flag : false,data : "已断开连接"})
		return
	}
	this.app.rpc.db.task.getRedTaskAward(null,uid,function(flag,data) {
		next(null,{flag : flag,data : data})
	})
}
//刷新红包任务
handler.refreshRedTask = function(msg,session,next) {
	var uid = session.get("uid")
	if(!uid){
		next(null,{flag : false,data : "已断开连接"})
		return
	}
	this.app.rpc.db.task.refreshRedTask(null,uid,function(flag,data) {
		next(null,{flag : flag,data : data})
	})
}